import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:张熳
 * Date:2025-10-26
 * Time:20:05
 */
public class Test {
    public static void main2(String[] args) {
        BinaryTree binaryTree = new BinaryTree();
        BinaryTree.TreeNode root = binaryTree.createTree();
        //获取树中节点的个数
        binaryTree.size(root);
        System.out.println("节点的个数：" + BinaryTree.nodeSize);//8

        int size = binaryTree.size1(root);
        System.out.println("节点的个数：" + size);//8

        //获取叶子节点的个数
        binaryTree.getLeafNodeCount(root);
        System.out.println("叶子节点的个数：" + BinaryTree.leafSize);//4

        int leaf = binaryTree.getLeafNodeCount1(root);
        System.out.println("叶子节点的个数：" + leaf);//4

        //获取第K层节点的个数
        binaryTree.getKLevelNodeCount(root,3);
        System.out.println("第k层节点的个数：" + BinaryTree.kSize);//4

        int kNodeSize = binaryTree.getKLevelNodeCount1(root,3);
        System.out.println("第k层节点的个数：" + kNodeSize);//4

        //获取二叉树的高度
        int TreeHeight = binaryTree.getTreeHeight(root);
        System.out.println("二叉树的高度：" + TreeHeight);

        //检测值为value的元素是否存在
        BinaryTree.TreeNode ret = binaryTree.findVal(root,'D');
        System.out.println(ret.val);//D

        //验证队列中可以存放null
        Queue<BinaryTree.TreeNode> queue = new LinkedList<>();
        queue.offer(null);
        queue.offer(null);
        queue.offer(null);
        queue.offer(null);
        System.out.print("queue中存放4个null的长度：");
        System.out.println(queue.size());//4

        //判断一棵树是不是完全二叉树
        System.out.println(binaryTree.isCompleteTree(root));//false
    }
    public static void main(String[] args) {
        BinaryTree binaryTree = new BinaryTree();
        BinaryTree.TreeNode root = binaryTree.createTree();

        System.out.println("前序遍历：");
        binaryTree.preOrder(root);//A B D E H C F G
        System.out.println();

        binaryTree.preorderTraversal1(root);
        System.out.println(binaryTree.list);//[A, B, D, E, H, C, F, G]

        List<Character> ret = binaryTree.preorderTraversal(root);
        System.out.println(ret);//[A, B, D, E, H, C, F, G]

        binaryTree.preOrderTraversal(root);//A B D E H C F G
        System.out.println();

        System.out.println("中序遍历：");
        binaryTree.inOrder(root);//D B E H A F C G
        System.out.println();

        List<Character> ret1 = binaryTree.inorderTraversal(root);
        System.out.println(ret1);//[D, B, E, H, A, F, C, G]

        binaryTree.inOrderTraversal(root);//D B E H A F C G
        System.out.println();

        System.out.println("后序遍历：");
        binaryTree.postOrder(root);//D H E B F G C A
        System.out.println();

        List<Character> ret2 = binaryTree.postorderTraversal(root);
        System.out.println(ret2);//[D, H, E, B, F, G, C, A]

        binaryTree.postOrderTraversal(root);//D H E B F G C A
        System.out.println();

        System.out.println("层序遍历：");
        binaryTree.levelOrder(root);//A B C D E F G H

        System.out.println();
        List<List<Character>> ret3 = binaryTree.levelOrder1(root);
        System.out.println(ret3);//[[A], [B, C], [D, E, F, G], [H]]
    }
}
